﻿namespace CodedUISample.Specification
{
    using System;

    using CodedUISample.StepDefinitions.Context;

    using LogTracerListener.SpecflowPlugin;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using TechTalk.SpecFlow;

    using UITest.Helpers;
    using UITest.Report;

    /// <summary>
    ///     The spec flow hooks.
    /// </summary>
    [DeploymentItem("StepDefinitions.dll")]

    // [DeploymentItem("Dependence\\CodedUIProviderWithMsTestContext.SpecFlowPlugin.dll")]
    [DeploymentItem("Dependence\\LogTracerListener.SpecflowPlugin.dll")]
    [Binding]
    public sealed class SpecFlowHooks
    {
        // For additional details on SpecFlow hooks see http://go.specflow.org/doc-hooks
        #region Public Properties

        /// <summary>
        ///     Gets or sets the proc helper.
        /// </summary>
        public ProcessHelper ProcHelper { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     The after scenario.
        /// </summary>
        [AfterScenario]
        public void AfterScenario()
        {
            //SeleniumSamplePageContextFactory.Factory.GetContext().CloseTestCase();
            //SeleniumSamplePageContextFactory.Factory.Dispose();

            this.ProcHelper.KillProcess("calc");
            
            // Comment out if IE is needed for testing
            // this.ProcHelper.KillProcess("IEDriverServer");
            // this.ProcHelper.KillProcess("iexplore");
        }

        /// <summary>
        ///     The before scenario.
        /// </summary>
        [BeforeScenario(Order = 0)]
        public void BeforeScenario()
        {
            this.ProcHelper = new ProcessHelper();
            this.ProcHelper.KillProcess("calc");

            // Comment out if IE is needed for testing
            // this.ProcHelper.KillProcess("IEDriverServer");
            // this.ProcHelper.KillProcess("iexplore");

            // SeleniumFactory.New(new IEProvider());
            SeleniumSamplePageContextFactory.Factory.New();
            //SeleniumSamplePageContextFactory.Factory.GetContext().NewTestCase((TestContext)FeatureContext.Current["TestContext"]);

            ReportFactory.New();
        }

        /// <summary>
        /// The foo.
        /// </summary>
        public void foo()
        {
            Type x = typeof(LogTracerListener);
        }

        #endregion
    }
}